package com.cqc.other.designPattern.strategyPattern.strategy1;

import org.junit.Test;

/**
 * @author cui
 * @date 2024/10/25 19:27
 * @description 计算保费
 * Insurance: 保险
 * Premium：额外的/保险费/高昂的
 **/
public class InsuranceService {


    @Test
    public void test() {
        double d = calculatePremium("YOUNG", true, "PREMIUM");
        System.out.println(d);
    }

    @Test
    public void test2() {
        double d = calculatePremium2("YOUNG", true, "PREMIUM");
        System.out.println(d);
    }

    /**
     * 没有使用策略模式
     */
    public double calculatePremium(String ageGroup, boolean hasPreExistingConditions, String planType) {
        if ("YONG".equals(ageGroup)) {
            if ("BASIC".equals(planType)) {
                return hasPreExistingConditions ? 500 : 300;
            } else if ("PREMIUM".equals(planType)) {
                return hasPreExistingConditions ? 700 : 500;
            }
        } else if ("ADULT".equals(ageGroup)) {
            if ("BASIC".equals(planType)) {
                return hasPreExistingConditions ? 600 : 400;
            } else if ("PREMIUM".equals(planType)) {
                return hasPreExistingConditions ? 800 : 600;
            }
        } else if ("SENIOR".equals(ageGroup)) {
            if ("BASIC".equals(planType)) {
                return hasPreExistingConditions ? 800 : 600;
            } else if ("PREMIUM".equals(planType)) {
                return hasPreExistingConditions ? 1000 : 800;
            }
        }
        return 0;
    }

    /**
     * 使用了策略模式 暂时没搞懂
     */
    public double calculatePremium2(String ageGroup, boolean hasPreExistingConditions, String planType) {
        AgeGroup group = AgeGroup.valueOf(ageGroup.toUpperCase());
        PremiumStrategy strategy = group.getStrategy(planType);
        return strategy.calculate(hasPreExistingConditions);
    }
}
